package com.xy.async.config;

import com.xy.async.job.AsyncJob;
import com.xy.async.job.CompJob;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static org.quartz.SimpleScheduleBuilder.simpleSchedule;

@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail asyncJobDetail() {
        return JobBuilder.newJob(AsyncJob.class)
                .withIdentity("asyncJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger asyncJobTrigger() {
        return TriggerBuilder.newTrigger()
                .forJob(asyncJobDetail())
                .withIdentity("asyncJobTrigger")
                .withSchedule(simpleSchedule()
                        .withIntervalInSeconds(10) // 每10秒执行一次
                        .repeatForever())
                .build();
    }

    @Bean
    public JobDetail compJobDetail() {
        return JobBuilder.newJob(CompJob.class)
                .withIdentity("compJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger compJobTrigger() {
        return TriggerBuilder.newTrigger()
                .forJob(compJobDetail())
                .withIdentity("compJobTrigger")
                .withSchedule(simpleSchedule()
                        .withIntervalInSeconds(10) // 每10秒执行一次
                        .repeatForever())
                .build();
    }
}
